using System.Windows.Forms;
using System.Collections.Generic;
namespace Woz
{
    /// <summary>
    /// contains an array of modes
    /// an array was used instead of a dictionary to save memory
    /// </summary>
    internal class Modes
    {
        /// <summary>
        /// constructor initializes the different modes
        /// </summary>
        public Modes()
        {
            this.mModes = new Woz.Mode[3];
        }

        public void AddMode(Woz.Mode pMode)
        {
            // dont overrun our boundary
            if (this.mModeCount >= this.mModes.Length)
            {
                return;
            }

            // add this mode to this slot
            this.mModes[this.mModeCount] = pMode;

            // increment the mode count
            this.mModeCount++;
        }

        public void UnCheckAllModeButtons()
        {
            // merely loop through all the modes and uncheck their buttons
            foreach (Woz.Mode mode in this.mModes)
            {
                // make sure this mode exists
                if (mode != null)
                {
                    // uncheck it
                    mode.Button.Checked = false;
                }
            }
        }

        public Woz.Mode this[string pModeName]
        {
            get
            {
                // loop through the modes and return the one that has this name
                foreach (Mode mode in this.mModes)
                {
                    if (mode.Name == pModeName)
                    {
                        return mode;
                    }
                }

                // if nothing is found just return null
                return null;
            }
        }

        public Woz.Mode this[ToolStripButton pModeButton]
        {
            get
            {
                // loop through the modes and return the one that has this button
                foreach (Woz.Mode mode in this.mModes)
                {
                    if (mode.Button == pModeButton)
                    {
                        return mode;
                    }
                }

                // if nothing is found just return null
                return null;
            }
        }

        /// <summary>
        /// array of the three different modes
        /// </summary>
        private Woz.Mode[] mModes;

        /// <summary>
        /// counts the number of modes we have loaded so far
        /// </summary>
        private short mModeCount;
    }
}